package fanfou4j.type;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import fanfou4j.org.json.JSONArray;
import fanfou4j.org.json.JSONObject;
import fanfou4j.util.DateUtil;

public class User implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 9172235822466555290L;
	private String id;
	private String name;
	private String screen_name;
	private String location;
	private String gender;
	private Date birthday;
	private String description;
	private String profile_image_url;
	private String url;
	private boolean protected_;
	private int friends_count;
	private int followers_count;
	private int favourites_count;
	private int statuses_count;
	private boolean following;
	private boolean notifications;
	private Date created_at;
	private String utc_offset;

	public User(JSONObject json) throws Exception {
		init(json);
	}

	private void init(JSONObject json) throws Exception {
		if (json != null) {
			id = json.getString("id");
			name=json.getString("name");
			screen_name=json.getString("screen_name");
			location=json.getString("location");
			gender=json.getString("gender");
			//2006-03-02
			birthday=DateUtil.parseDate(json.getString("birthday"), "yyyy-MM-dd");
			description=json.getString("description");
			profile_image_url=json.getString("profile_image_url");
			url=json.getString("url");
			protected_=json.getBoolean("protected");
			friends_count=json.getInt("friends_count");
			favourites_count=json.getInt("favourites_count");
			statuses_count=json.getInt("statuses_count");
			following=json.getBoolean("following");
			notifications=json.getBoolean("notifications");
			//Fri Apr 17 01:34:06 +0000 2009
			created_at=DateUtil.parseDate(json.getString("created_at"), "EEE MMM dd HH:mm:ss ZZZZZ yyyy");
			utc_offset=json.getString("utc_offset");					
		}

	}
	
	public static List<User> getUserList(JSONArray array) throws Exception{
		int size=array.length();
		List<User> list=new ArrayList<User>();
		for (int i = 0; i < size; i++) {
			list.add(new User(array.getJSONObject(i)));
		}
		return list;
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getScreen_name() {
		return screen_name;
	}

	public String getLocation() {
		return location;
	}

	public String getGender() {
		return gender;
	}

	public Date getBirthday() {
		return birthday;
	}

	public String getDescription() {
		return description;
	}

	public String getProfile_image_url() {
		return profile_image_url;
	}

	public String getUrl() {
		return url;
	}

	public boolean isProtected_() {
		return protected_;
	}

	public int getFriends_count() {
		return friends_count;
	}

	public int getFollowers_count() {
		return followers_count;
	}

	public int getFavourites_count() {
		return favourites_count;
	}

	public int getStatuses_count() {
		return statuses_count;
	}

	public boolean isFollowing() {
		return following;
	}

	public boolean isNotifications() {
		return notifications;
	}

	public Date getCreated_at() {
		return created_at;
	}

	public String getUtc_offset() {
		return utc_offset;
	}
	
	

	@Override
	public String toString() {
		return "User [id=" + id + ", name=" + name + ", screen_name="
				+ screen_name + ", location=" + location + ", gender=" + gender
				+ ", birthday=" + birthday + ", description=" + description
				+ ", profile_image_url=" + profile_image_url + ", url=" + url
				+ ", protected_=" + protected_ + ", friends_count="
				+ friends_count + ", followers_count=" + followers_count
				+ ", favourites_count=" + favourites_count
				+ ", statuses_count=" + statuses_count + ", following="
				+ following + ", notifications=" + notifications
				+ ", created_at=" + created_at + ", utc_offset=" + utc_offset
				+ "]";
	}

	
	

}
